package com.pd.backend.service.impl;

import com.pd.backend.dao.PdAreaDao;
import com.pd.backend.dao.PdOrderDao;
import com.pd.backend.entity.PdTaskTransport;
import com.pd.backend.dao.PdTaskTransportDao;
import com.pd.backend.service.PdTaskTransportService;
import com.pd.backend.vo.req.PdOrderGetPageReqVo;
import com.pd.backend.vo.req.PdOrderReqVo;
import com.pd.backend.vo.req.ReceiverCityVo;
import com.pd.backend.vo.resp.GetPageVo;
import com.pd.backend.vo.resp.PdOrderRespVo;
import com.pd.backend.vo.resp.R;
import com.pd.backend.vo.resp.TransportOrderManagerPage;
import lombok.SneakyThrows;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 运输任务表(PdTaskTransport)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:35
 */
@Service("pdTaskTransportService")
public class PdTaskTransportServiceImpl implements PdTaskTransportService {
    @Resource
    private PdTaskTransportDao pdTaskTransportDao;


    @Autowired
    private PdOrderDao pdOrderDao;

    @Autowired
    private PdAreaDao pdAreaDao;
    /**
     * 查询运单列表业务接口
     *
     * @param  pdOrderReqVo
     * @return
     */

    @Override
    public R<GetPageVo<TransportOrderManagerPage>> getTransportPage( PdOrderGetPageReqVo pdOrderGetPageReqVo) {
        GetPageVo<TransportOrderManagerPage> p = new GetPageVo<>();
       List<PdTaskTransport> ptts =  pdTaskTransportDao.selectToPage(pdOrderGetPageReqVo);
        System.out.println(ptts);
        ArrayList<TransportOrderManagerPage> transportOrderManagerPages = new ArrayList<>();
        //对order封装



        for (PdTaskTransport ptt : ptts) {
            TransportOrderManagerPage transportOrderManagerPage = new TransportOrderManagerPage();
            transportOrderManagerPage.setId(ptt.getId());
            transportOrderManagerPage.setStatus(ptt.getStatus().toString());
            transportOrderManagerPage.setCreateTime(ptt.getCreateTime());
            ReceiverCityVo receiverCityVo = pdAreaDao.selectReceiver(pdOrderGetPageReqVo);
            PdOrderRespVo pdOrderRespVo = pdOrderDao.selectOrderOne(pdOrderGetPageReqVo);
            pdOrderRespVo.setReceiverCity(receiverCityVo);
            transportOrderManagerPage.setOrder(pdOrderRespVo);
            transportOrderManagerPages.add(transportOrderManagerPage);
        }

        System.out.println(transportOrderManagerPages);
        GetPageVo<TransportOrderManagerPage> transportOrderManagerPageGetPageVo = new GetPageVo<>();
        transportOrderManagerPageGetPageVo.setItems(transportOrderManagerPages);
        transportOrderManagerPageGetPageVo.setPage(1);
        transportOrderManagerPageGetPageVo.setPagesize(10);
        transportOrderManagerPageGetPageVo.setPages(100);
        transportOrderManagerPageGetPageVo.setCounts(10);

//        if (Objects.isNull(transportOrderManagerPageGetPageVo)||transportOrderManagerPageGetPageVo.){
//            return R.error("数据查询失败");
//        }
        return R.ok(transportOrderManagerPageGetPageVo);
    }
}
